package com.own.business.question.entity.dto;

import com.own.business.question.common.base.ReplyEnvironment;
import com.own.business.question.entity.bo.PracticeHistoryBo;
import com.own.component.common.base.entity.BaseDto;
import com.own.constant.ConstantBeanSuffix;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.math.BigDecimal;

/**
 * PracticeHistoryDto
 *
 * @author chenxueli
 * @date 2021/05/14 15:49:28
 */
@Schema(description = "练习流水表" + ConstantBeanSuffix.DTO)
@Getter
@Setter
@ToString
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class PracticeHistoryDto extends BaseDto<PracticeHistoryBo> {

    @Schema(description = "用户id")
    private Long userId;

    @Schema(description = "练习id")
    private Long practiceId;

    @Schema(description = "题目id")
    private Long questionId;

    @Schema(description = "判定结果 0-1")
    private BigDecimal judging;

    @Schema(description = "用户答案")
    private String answer;

    @Schema(description = "题目用时（ms）")
    private Long useTime;

    @Schema(description = "作答环境")
    private ReplyEnvironment replyEnvironment;

    @Schema(description = "作答状态 0=未作答 1=已作答 2=保存 3=废弃")
    private Integer status;

    @Schema(description = "答案的打乱顺序")
    private String keySortOrder;

    /**
     * 转业务层对象
     *
     * @param entity 原业务层对象
     * @return 业务层对象
     */
    @Override
    public PracticeHistoryBo toBo(PracticeHistoryBo entity) {
        if (entity == null) {
            entity = new PracticeHistoryBo();
        }
        entity.setUserId(userId);
        entity.setPracticeId(practiceId);
        entity.setQuestionId(questionId);
        entity.setJudging(judging);
        entity.setAnswer(answer);
        entity.setUseTime(useTime);
        entity.setReplyEnvironment(replyEnvironment);
        entity.setStatus(status);
        entity.setKeySortOrder(keySortOrder);
        return super.toBo(entity);
    }

}
